package com.boge.entity;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import com.boge.parse.Amf3Stream;

import flex.messaging.io.amf.Amf3Input;

public class GameInput {

	private Amf3Input amf3Input;
	private ByteArrayInputStream inputStream;

	public GameInput(byte[] buf) {
		this.inputStream = new ByteArrayInputStream(buf);
		amf3Input = Amf3Stream.newAmf3Input(inputStream);
	}
	
	public GameInput(ByteArrayInputStream inputStream) {
		this.inputStream = inputStream;
		amf3Input = Amf3Stream.newAmf3Input(inputStream);
	}
	
	public void reset() {
		inputStream.reset();
		amf3Input.reset();
	}
	
	public void close() throws IOException {
		if(inputStream!=null) this.inputStream.close();
		if(amf3Input!=null) amf3Input.close();
		inputStream = null;
		amf3Input = null;
	}
	
	public int available() throws IOException {
		return amf3Input.available();
	}
	
	public int readInt() throws IOException {
		return amf3Input.readInt();
	}
	
	public String readUTF() throws IOException {
		return amf3Input.readUTF();
	}
	
	public boolean readBoolean() throws IOException {
		return amf3Input.readBoolean();
	}
	
	public long readLong() throws IOException {
		return amf3Input.readLong();
	}
	
	public float readFloat() throws IOException {
		return amf3Input.readFloat();
	}
	
	public double readDouble() throws IOException {
		return amf3Input.readDouble();
	}
	
	public Object readObject() throws ClassNotFoundException, IOException  {
		return amf3Input.readObject();
	}

	public Amf3Input getAmf3Input() {
		return amf3Input;
	}

	public ByteArrayInputStream getInputStream() {
		return inputStream;
	}
	
}
